package org.budo.support.spring.session.repository.map;

import java.util.UUID;

import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSession;
import org.springframework.session.MapSessionRepository;

/**
 * @author lmw
 */
public class BudoMapSessionRepository extends MapSessionRepository {
    private Integer defaultMaxInactiveInterval;

    /**
     * 覆盖方法
     */
    public ExpiringSession createSession() {
        ExpiringSession session = new MapSession(UUID.randomUUID().toString().replace("-", "")); // 指定ID
        if (this.defaultMaxInactiveInterval != null) {
            session.setMaxInactiveIntervalInSeconds(this.defaultMaxInactiveInterval);
        }
        return session;
    }

    public void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval) {
        this.defaultMaxInactiveInterval = Integer.valueOf(defaultMaxInactiveInterval);
    }
}
